package com.molyfun.parents.activity.record.itemview;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.GameViewerActivity;
import com.molyfun.parents.activity.common.ImageViewerActivity;
import com.molyfun.parents.activity.setting.WebViewActivity;
import com.molyfun.parents.rest.QiniuSDK;
import com.molyfun.parents.rest.RestClient;
import com.molyfun.parents.rest.bean.RecordResponse;
import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:11/3/16.
 * <p>
 * 此类为容器
 */
public class RecordFileView extends BaseRecordView {

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.record_img)
    ImageView mRecordImg;
    @InjectView(R.id.record_user)
    TextView mRecordUser;

    public RecordFileView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public RecordFileView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public RecordFileView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_record_image, this);
        ButterKnife.inject(this);
    }

    /**
     * init view
     */
    public void initData(RecordResponse.RecordBean recordBean) {
        if (recordBean != null) {
            mRecordBean = recordBean;
            mRecordImg.setImageResource(R.mipmap.ic_file_holder);
            mRecordUser.setText(mRecordBean.getUsername());
            mRecordImg.setOnClickListener(this);
            mRecordImg.setOnLongClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.record_img:
                GameViewerActivity.startActivity(context, RestClient.ONLINE_OFFICE_FILE_URL_HEAD + mRecordBean.getUrl());
                break;
        }
    }

}